//
//  DataUtil.h
//  hvECG
//
//  Created by Will on 7/31/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>   //for iOS/Mac Catalyst
//#import <Cocoa/Cocoa.h>     //for MacOS

typedef void(^HeartBeatRateDetected)(int hbr);
typedef void(^SamplingRateReceived)(int rate);
typedef void(^DeviceIdReceived)(NSString* deviceId);
typedef void(^DeviceIsReadyToRecord)(void);
typedef void(^DataReceived)(NSArray *);
typedef void(^DataErrorDetected)(NSError* error);
typedef void(^LeadsConnectivityStatusUpdated)(short cr, short cl, short c1, short c2, short c3, short c4, short c5, short c6);
typedef void(^BatteryVolumnReceived)(int batvol);
typedef void(^DeviceAdditionalInfoReceived)(BOOL sampleDoubled, short adBits, short adRange, float amplifier, short deviceVersion, BOOL isNewDevice);

@interface DataUtil: NSObject {
	short HR, sample;
    int smoothType;
    BOOL baselineEnabled, sample_doubled;
    int broken_lost, broken_seq, broken_seq1;
    short *single_data;
    short** data_decompressed;
    short** data_decompressed_2;

    int c1, c2, c3, c4, c5, c6, cr, cl;
    Byte keyByte;
    int zero;
    double uVpb;
    double lpassFreq;
    double hpassFreq;
    double notchFreq;
    int adbits, adpeak, amp, pps, batvol;
    short deviceVersion;
    
    BOOL initial_Done, pingBack_sn, pingBack_pps, pingBack_adbits, isNewDevice, pingBack_adrange, pingBack_amp, pushingData;
    
    BOOL filtersOn;
}

@property (nonatomic) short HR, dataLost, tagIndex, nextTagIndex, compressMethod, compressMethod_next, deviceSubversion, newBornMode;
@property (nonatomic) int smoothType;
@property (nonatomic) BOOL baselineEnabled, filtersOn;
@property (nonatomic) double lpassFreq, hpassFreq, notchFreq;
@property (nonatomic) HeartBeatRateDetected heartBeatRateDetected;
@property (nonatomic) SamplingRateReceived samplingRateReceived;
@property (nonatomic) DeviceIdReceived deviceIdReceived;
@property (nonatomic) DataReceived dataReceived;
@property (nonatomic) DeviceIsReadyToRecord deviceIsReadyToRecord;
@property (nonatomic) DataErrorDetected dataErrorDetected;
@property (nonatomic) LeadsConnectivityStatusUpdated leadsConnectivityStatusUpdated;
@property (nonatomic, strong) NSMutableArray *buffer;

@property (nonatomic) BatteryVolumnReceived batteryVolumnReceived;
@property (nonatomic) DeviceAdditionalInfoReceived deviceAdditionalInfoReceived;

- (id)init;
- (void)declearFilterClasses;
- (void)deposeFilterClasses;

- (void)wilsonConverter:(short *)data;
- (void)convertDataToBinbytesAndPushInQueue:(Byte*)bytes ToQueue:(NSMutableArray*)queue bytesCount:(long)length;
- (short**)popAndProcessDataFromQueue:(NSMutableArray*)queue numberOfSet:(int)numberOfSet;
- (short**)popAndProcessDataFromQueue_new:(NSMutableArray*)queue numberOfSet:(int)numberOfSet;
- (NSArray *)filterAndConvert8DataTo12Array:(short **)data dataLength:(int)length doWilsonConvert:(BOOL)wilsonConvert;
- (void)doTest;
- (void)receivedData:(NSData *)data;
- (void)popoutData;
- (void)setParameters:(int)sample sampleDoubled:(BOOL)sampleDoubled adBits:(int)adBits adRange:(int)adRange amp:(int)ampifier deviceVersion:(int)deviceMainVersion isNewDevice:(BOOL)NewDevice;

@end
